package com.currency.mall.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.annotation.Nullable;
import android.widget.Button;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.currency.mall.R;
import com.currency.mall.entity.OrderInfo;
import com.currency.mall.util.TimeUtil;
import com.currency.mall.util.Util;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Created by Administrator on 2018/12/5.
 */

public class OrderPositionAdapter extends BaseQuickAdapter<OrderInfo, BaseViewHolder> {

    public OrderPositionAdapter(@Nullable List<OrderInfo> data, Context context) {
        super(R.layout.item_order_position, data);
    }

    @Override
    protected void convert(BaseViewHolder helper, OrderInfo orderInfo) {
        helper.addOnClickListener(R.id.btn_entrust_settlement);
        helper.setText(R.id.tv_bid_name,orderInfo.getSharesName()+" ("+orderInfo.getSharesCode()+" )");
        helper.setText(R.id.tv_start_time,orderInfo.getBeginTime().substring(0,10));
        helper.setText(R.id.tv_end_time,orderInfo.getEndTime().substring(0,10));
        if("DAY".equals(orderInfo.getRoyaltyType())){
            helper.setText(R.id.tv_option_cycle,orderInfo.getRoyaltyVal()+"天");
        }else  if("WEEK".equals(orderInfo.getRoyaltyType())){
            helper.setText(R.id.tv_option_cycle,orderInfo.getRoyaltyVal()+"周");
        }else  if("MONTH".equals(orderInfo.getRoyaltyType())){
            helper.setText(R.id.tv_option_cycle,orderInfo.getRoyaltyVal()+"月");
        }
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");//设置日期格式
        String day = TimeUtil.daysOfTwo(df.format(new Date()),orderInfo.getEndTime().substring(0,10));
        helper.setText(R.id.tv_surplus_time,day);
        helper.setText(R.id.tv_execution_price,orderInfo.getBeginSum());
        helper.setText(R.id.tv_nominal_principal,Util.formatTosepara(Double.parseDouble(orderInfo.getNameSum())));
        helper.setText(R.id.tv_current_stock_price,orderInfo.getPriceNow());//当前股价
        helper.setText(R.id.tv_floating_profit,Util.formatTosepara(Double.parseDouble(orderInfo.getFloatProfit())));//盈亏浮动
        Button btn = helper.getView(R.id.btn_entrust_settlement);
        if("false".equals(orderInfo.getSwitchClose())){
            btn.setBackgroundResource(R.drawable.settlemente_not_clickbg);
            btn.setTextColor(Color.parseColor("#FFFFFF"));
        }else{
            btn.setBackgroundResource(R.drawable.red_write_bg);
            btn.setTextColor(Color.parseColor("#E51C23"));
        }
    }

}
